home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 4 / ETO Development Tools 4.iso / Tools - Objects / MacApp / MacApp 2.0.1 / MacApp CD Release / MacApp 2.0.1 (Hard Disk Ready) / Libraries / UViewCoords.a < prev   
Text File  |  1990-10-25  |  23KB  |  795 lines

  1. ;=============================================================================
  2. ; Copyright © 1988-1990 Apple Computer, Inc.  All rights reserved.
  3. ; UViewCoords assembly language routines
  4.  
  5.                 Blanks        On
  6.                 String        AsIs
  7.                 Case        On
  8.  
  9.                 Print        Off
  10.                 Include     'Macros.a'
  11.  
  12.                 LOAD            'ProgStrucMacs.d'
  13.                 LOAD            'FlowCtlMacs.d'
  14.                 Print        On
  15.  
  16.     case off
  17.                 Seg         'MAUtilitiesRes'
  18.  
  19. kMaxCoord        Equ         30000                ; Max coordinate for small views.
  20.  
  21. ;---------------------------------------------
  22.                 Macro
  23.                 ResvLong
  24.     CASE on
  25.             If qDebug Then
  26.                 Move.L        #'rgrg',-(SP)
  27.             Else
  28.                 Clr.L        -(SP)
  29.             EndIf
  30.     CASE off
  31.                 EndM
  32.  
  33. ;---------------------------------------------
  34.                 Macro
  35.                 PopRts        &amt
  36.                 
  37.                 LclA        &size
  38.         &size:    SetA        &Eval(&amt)
  39.                 MoveA.L     (SP)+,A0            ; A0 := return address
  40.             If &size > 8 Then
  41.                 Lea         &size(SP),SP
  42.             Else
  43.                 AddQ.W        #&size,SP
  44.             EndIf
  45.                 Jmp         (A0)
  46.                 EndM
  47.  
  48. ********************************************************************************************
  49. *                PROCEDURE PtToVPt (thePt: Point; VAR theVPt: VPoint);
  50. *                Converts the given Point to a VPoint.
  51. *
  52. *                Trashes:    D0,A0
  53. ********************************************************************************************
  54. PtToVPt         Proc        Export
  55.  
  56. StackFrame        Record        0,Increment
  57. RetAddr         Ds.L        1
  58. theVPt            Ds.L        1
  59. thePt            Ds.W        2
  60. ArgSize         Equ         *-4
  61.                 EndR
  62.  
  63.                 With        StackFrame
  64.  
  65.                 MoveA.L     theVPt(SP),A0        ; A0 := address of theVPt.
  66.                 Move.W        thePt(SP),D0        ; D0 := thePt.v.
  67.                 Ext.L        D0                    ; Convert vertical coord to a long.
  68.                 Move.L        D0,(A0)+            ; Save it in theVPt.v.
  69.                 Move.W        thePt+2(SP),D0        ; D0 := thePt.h.
  70.                 Ext.L        D0                    ; Convert horizontal coord to a long.
  71.                 Move.L        D0,(A0)             ; Save it in theVPt.h.
  72.  
  73.                 PopRts        ArgSize             ; Pop arguments off stack and return
  74.  
  75.                 EndProc
  76.  
  77. ********************************************************************************************
  78. *                FUNCTION VPtToPt (theVPt: VPoint): Point;
  79. *                Converts the given VPoint to a Point.
  80. *
  81. *                Trashes:    D0,D1,D2,A0
  82. ********************************************************************************************
  83. VPtToPt         Func        Export
  84.  
  85. StackFrame        Record        0,Increment
  86. RetAddr         Ds.L        1
  87. theVPt            Ds.L        1
  88. ArgSize         Equ         *-4
  89. RetValue        Ds.W        2
  90.                 EndR
  91.  
  92.                 With        StackFrame
  93.  
  94.                 MoveA.L     theVPt(SP),A0        ; A0 := address of theVPt.
  95.                 Move.L        #kMaxCoord,D1
  96.                 Move.L        D1,D2                ; Saves a couple bytes and is faster
  97.                 Neg.L        D2                    ; D2 := -kMaxCoord
  98.  
  99.                 Move.L        (A0)+,D0            ; Get vertical coord of theVPt
  100.                 Cmp.L        D1,D0                ; Is theVPt.v > kMaxCoord?
  101.                 Bgt.S        @1                    ; Yes, branch.
  102.                 Cmp.L        D2,D0                ; No.  Is theVPt.v < -kMaxCoord?
  103.                 Bge.S        @2                    ; No, branch.
  104.                 Move.L        D2,D0                ; Set value to -kMaxCoord
  105.                 Bra.S        @2
  106. @1
  107.                 Move.L        D1,D0                ; Set value to kMaxCoord
  108. @2
  109.                 Move.W        D0,RetValue(SP)     ; RetValue.v := D0.
  110.  
  111.                 Move.L        (A0),D0             ; Get horizontal coord of theVPt.
  112.                 Cmp.L        D1,D0                ; Is theVPt.h > kMaxCoord?
  113.                 Bgt.S        @3                    ; Yes, branch.
  114.                 Cmp.L        D2,D0                ; No.  Is theVPt.h < -kMaxCoord?
  115.                 Bge.S        @4                    ; No, branch.
  116.                 Move.L        D2,D0                ; Set value to -kMaxCoord.
  117.                 Bra.S        @4
  118. @3
  119.                 Move.L        D1,D0                ; Set value to kMaxCoord.
  120. @4
  121.                 Move.W        D0,RetValue+2(SP)    ; RetValue.h := D0.
  122.  
  123.                 PopRts        ArgSize             ; Pop arguments off stack and return.
  124.  
  125.                 EndProc
  126.  
  127. ********************************************************************************************
  128. *                PROCEDURE RectToVRect (theRect: Rect; VAR theVRect: VRect);
  129. *                Converts the given Rect to a VRect.
  130. *
  131. *                Trashes:    D0,A0,A1
  132. ********************************************************************************************
  133. RectToVRect     Proc        Export
  134.  
  135. StackFrame        Record        0,Increment
  136. RetAddr         Ds.L        1
  137. theVRect        Ds.L        1
  138. theRect         Ds.L        1
  139. ArgSize         Equ         *-4
  140.                 EndR
  141.  
  142.                 With        StackFrame
  143.  
  144.                 MoveA.L     theRect(SP),A0        ; Get address of theRect.
  145.                 MoveA.L     theVRect(SP),A1     ; Get address of theVRect.
  146.  
  147.                 Move.W        (A0)+,D0            ; Copy top.
  148.                 Ext.L        D0
  149.                 Move.L        D0,(A1)+
  150.                 Move.W        (A0)+,D0            ; Copy left.
  151.                 Ext.L        D0
  152.                 Move.L        D0,(A1)+
  153.                 Move.W        (A0)+,D0            ; Copy bottom.
  154.                 Ext.L        D0
  155.                 Move.L        D0,(A1)+
  156.                 Move.W        (A0),D0             ; Copy right.
  157.                 Ext.L        D0
  158.                 Move.L        D0,(A1)
  159.  
  160.                 PopRts        ArgSize             ; Pop arguments off stack and return.
  161.  
  162.                 EndProc
  163.  
  164. ********************************************************************************************
  165. *                PROCEDURE VRectToRect (theVRect: VRect; VAR theRect: Rect);
  166. *                Converts the given VRect to a Rect.
  167. *
  168. *                Trashes:    D0,D1,D2,A0,A1
  169. ********************************************************************************************
  170. VRectToRect     Proc        Export
  171.  
  172. StackFrame        Record        0,Increment
  173. RetAddr         Ds.L        1
  174. theRect         Ds.L        1
  175. theVRect        Ds.L        1
  176. ArgSize         Equ         *-4
  177.                 EndR
  178.  
  179.                 With        StackFrame
  180.  
  181.                 MoveA.L     theRect(SP),A1        ; Get address of theVRect.
  182.                 ; VPtToPt must not futz with A1!!!
  183.  
  184.                 ResvLong                        ; Space for result of VPtToPt.
  185.                 Move.L        theVRect+4(SP),-(SP); Push address of theVRect.topLeft.
  186.                 Bsr         VPtToPt             ; Convert topLeft.
  187.                 Move.L        (SP)+,(A1)+         ; Save topLeft.
  188.  
  189.                 ResvLong                        ; Space for result of VPtToPt.
  190.                 Move.L        theVRect+4(SP),-(SP); Push address of theVRect.botRight.
  191.                 AddQ.L        #8,(SP)
  192.                 Bsr         VPtToPt             ; Convert botRight.
  193.                 Move.L        (SP)+,(A1)            ; Save botRight.
  194.  
  195.                 PopRts        ArgSize             ; Pop arguments off stack and return.
  196.  
  197.                 EndProc
  198.  
  199. ********************************************************************************************
  200. *                PROCEDURE AddVPt (srcVPt: VPoint; VAR dstVPt: VPoint);
  201. *                Adds srcVPt to dstVPt, leaving result in dstVPt.
  202. *
  203. *                Trashes:    A0,A1,D0
  204. ********************************************************************************************
  205. AddVPt            Proc        Export
  206.  
  207. StackFrame        Record        0,Increment
  208. RetAddr         Ds.L        1
  209. dstVPt            Ds.L        1
  210. srcVPt            Ds.L        1
  211. ArgSize         Equ         *-4
  212.                 EndR
  213.  
  214.                 With        StackFrame
  215.  
  216.                 MoveA.L     srcVPt(SP),A0        ; Get addresses.
  217.                 MoveA.L     dstVPt(SP),A1
  218.                 Move.L        (A0)+,D0            ; Add vertical coordinate.
  219.                 Add.L        D0,(A1)+
  220.                 Move.L        (A0),D0             ; Add horizontal coordinate.
  221.                 Add.L        D0,(A1)
  222.  
  223.                 PopRts        ArgSize             ; Pop arguments off stack and return.
  224.  
  225.                 EndProc
  226.  
  227. ********************************************************************************************
  228. *                PROCEDURE SubVPt (srcVPt: VPoint; VAR dstVPt: VPoint);
  229. *                Subtracts srcVPt from dstVPt, leaving result in dstVPt.
  230. *
  231. *                Trashes:    A0,A1,D0
  232. ********************************************************************************************
  233. SubVPt            Proc        Export
  234.  
  235. StackFrame        Record        0,Increment
  236. RetAddr         Ds.L        1
  237. dstVPt            Ds.L        1
  238. srcVPt            Ds.L        1
  239. ArgSize         Equ         *-4
  240.                 EndR
  241.  
  242.                 With        StackFrame
  243.  
  244.                 MoveA.L     srcVPt(SP),A0        ; Get addresses.
  245.                 MoveA.L     dstVPt(SP),A1
  246.                 Move.L        (A0)+,D0            ; Subtract vertical coordinate.
  247.                 Sub.L        D0,(A1)+
  248.                 Move.L        (A0),D0             ; Subtract horizontal coordinate.
  249.                 Sub.L        D0,(A1)
  250.  
  251.                 PopRts        ArgSize             ; Pop arguments off stack and return.
  252.  
  253.                 EndProc
  254.  
  255. ********************************************************************************************
  256. *                PROCEDURE SetVPt (VAR vPt: VPoint; h, v: VCoordinate);
  257. *                Sets vPt to the given horizontal and vertical coordinates.
  258. *
  259. *                Trashes:    A0
  260. ********************************************************************************************
  261. SetVPt            Proc        Export
  262.  
  263. StackFrame        Record        0,Increment
  264. RetAddr         Ds.L        1
  265. v                Ds.L        1
  266. h                Ds.L        1
  267. VPt             Ds.L        1
  268. ArgSize         Equ         *-4
  269.                 EndR
  270.  
  271.                 With        StackFrame
  272.  
  273.                 MoveA.L     VPt(SP),A0            ; Get address of vPt.
  274.                 Move.L        v(SP),(A0)+         ; Copy vertical coordinate.
  275.                 Move.L        h(SP),(A0)            ; Copy horizontal coordinate.
  276.  
  277.                 PopRts        ArgSize             ; Pop arguments off stack and return.
  278.  
  279.                 EndProc
  280.  
  281. ********************************************************************************************
  282. *                FUNCTION EqualVPt (pt1, pt2: VPoint): BOOLEAN;
  283. *                Returns true if pt1 and pt2 are equal.
  284. *
  285. *                Trashes:    D0,A0,A1
  286. ********************************************************************************************
  287. EqualVPt        Func        Export
  288.  
  289. StackFrame        Record        0,Increment
  290. RetAddr         Ds.L        1
  291. pt2             Ds.L        1
  292. pt1             Ds.L        1
  293. ArgSize         Equ         *-4
  294. RetValue        Ds.W        1
  295.                 EndR
  296.  
  297.                 With        StackFrame
  298.  
  299.                 MoveA.L     pt1(SP),A0            ; Get address of pt1.
  300.                 MoveA.L     pt2(SP),A1            ; Get address of pt2.
  301.                 CmpM.L        (A0)+,(A1)+         ; Are vertical coordinates equal?
  302.                 Bne.S        @1                    ; If they weren't equal, we're already done
  303.  
  304.                 CmpM.L        (A0)+,(A1)+         ; Are horizontal coordinates equal?
  305.  
  306.         @1:     Seq         D0                    ; true if equal
  307.                 Neg.B        D0                    ; Blaise wants false=0, true=1
  308.                 Move.B        D0,RetValue(SP)     ; Set result
  309.  
  310.                 PopRts        ArgSize             ; Pop arguments off stack and return.
  311.  
  312.                 EndProc
  313.  
  314. ********************************************************************************************
  315. *                PROCEDURE SetVRect (VAR r: VRect; left, top, right, bottom: VCoordinate);
  316. *                Sets r to the given coordinates.
  317. *
  318. *                Trashes:    A0
  319. ********************************************************************************************
  320. SetVRect        Proc        Export
  321.  
  322. StackFrame        Record        0,Increment
  323. RetAddr         Ds.L        1
  324. bottom            Ds.L        1
  325. right            Ds.L        1
  326. top             Ds.L        1
  327. left            Ds.L        1
  328. r                Ds.L        1
  329. ArgSize         Equ         *-4
  330.                 EndR
  331.  
  332.                 With        StackFrame
  333.  
  334.                 MoveA.L     r(SP),A0            ; Get address of r.
  335.                 Move.L        top(SP),(A0)+        ; Set the coordinates.
  336.                 Move.L        left(SP),(A0)+
  337.                 Move.L        bottom(SP),(A0)+
  338.                 Move.L        right(SP),(A0)
  339.  
  340.                 PopRts        ArgSize             ; Pop arguments off stack and return.
  341.  
  342.                 EndProc
  343.  
  344. ********************************************************************************************
  345. *                PROCEDURE OffsetVRect (VAR r: VRect; dh, dv: VCoordinate);
  346. *                Offsets the coordinates of the given rectangle by dh and dv.
  347. *
  348. *                Trashes:    A0,D0,D1
  349. ********************************************************************************************
  350. OffsetVRect     Proc        Export
  351.  
  352. StackFrame        Record        0,Increment
  353. RetAddr         Ds.L        1
  354. dv                Ds.L        1
  355. dh                Ds.L        1
  356. r                Ds.L        1
  357. ArgSize         Equ         *-4
  358.                 EndR
  359.  
  360.                 With        StackFrame
  361.  
  362.                 MoveA.L     r(SP),A0            ; Get address of r.
  363.                 Move.L        dh(SP),D0            ; Get horizontal offset.
  364.                 Move.L        dv(SP),D1            ; Get vertical offset.
  365.                 Add.L        D1,(A0)+            ; Add vertical offset to top.
  366.                 Add.L        D0,(A0)+            ; Add horizontal offset to left.
  367.                 Add.L        D1,(A0)+            ; Add vertical offset to bottom.
  368.                 Add.L        D0,(A0)             ; Add horizontal offset to right.
  369.  
  370.                 PopRts        ArgSize             ; Pop arguments off stack and return.
  371.  
  372.                 EndProc
  373.  
  374. ********************************************************************************************
  375. *                PROCEDURE InsetVRect (VAR r: VRect; dh, dv: VCoordinate);
  376. *                Insets the given rectangle by dh and dv.
  377. *
  378. *                Trashes:    A0,A1,D0,D1
  379. ********************************************************************************************
  380. InsetVRect        Proc        Export
  381.                 Import        ValidateRect
  382.  
  383. StackFrame        Record        0,Increment
  384. RetAddr         Ds.L        1
  385. dv                Ds.L        1
  386. dh                Ds.L        1
  387. r                Ds.L        1
  388. ArgSize         Equ         *-4
  389.                 EndR
  390.  
  391.                 With        StackFrame
  392.  
  393.                 MoveA.L     r(SP),A0            ; Get address of r.
  394.                 MoveA.L     A0,A1
  395.                 Move.L        dh(SP),D0            ; Get horizontal offset.
  396.                 Move.L        dv(SP),D1            ; Get vertical offset.
  397.                 Add.L        D1,(A1)+            ; Add vertical offset to top.
  398.                 Add.L        D0,(A1)+            ; Add horizontal offset to left.
  399.                 Sub.L        D1,(A1)+            ; Subtract vertical offset to bottom.
  400.                 Sub.L        D0,(A1)             ; Subtract horizontal offset to right.
  401.  
  402.                 Bsr         ValidateRect
  403.  
  404.                 PopRts        ArgSize             ; Pop arguments off stack and return.
  405.  
  406.                 EndProc
  407.  
  408. ********************************************************************************************
  409. *                PROCEDURE Pt2VRect (pt1, pt2: VPoint; VAR: dstRect: VRect);
  410. *                Set dstRect to the given top-left and bottom-right.
  411. *
  412. *                Trashes:    D0,D1,A0,A1
  413. ********************************************************************************************
  414. Pt2VRect        Proc        Export
  415.  
  416. StackFrame        Record        0,Increment
  417. RetAddr         Ds.L        1
  418. dstRect         Ds.L        1
  419. pt2                Ds.L        1
  420. pt1                 Ds.L        1
  421. ArgSize         Equ         *-4
  422.                 EndR
  423.  
  424.                 With        StackFrame
  425.  
  426.                 MoveA.L     dstRect(SP),A0        ; Get address of dstRect into A0.
  427.                 MoveA.L     pt1(SP),A1            ; Get address of pt1 into A1.
  428.                 MoveM.L     (A1),D0/D1            ; Move topLeft
  429.                 MoveM.L     D0/D1,(A0)
  430.                 MoveA.L     pt2(SP),A1             ; Get address of pt2 into A1.
  431.                 MoveM.L     (A1),D0/D1            ; Move botRight
  432.                 MoveM.L     D0/D1,8(A0)
  433.  
  434.                 Lea         8(A0),A1            ; A1 := dstRect.botRight
  435.  
  436.                ; At this point, D0 = bottom, D1 = right
  437.                ; A0 => dstRect.topLeft, A1 => dstRect.botRight
  438.  
  439.                CmpM.L        (A0)+,(A1)+            ; Is top > bottom?
  440.                Bge.S        @1                  ; No, skip swap
  441.                Move.L        -4(A0),-4(A1)       ; bottom := top
  442.                Move.L        D0,-4(A0)            ; top := bottom
  443.  
  444.        @1:     CmpM.L        (A0)+,(A1)+            ; Is left > right?
  445.                Bge.S        @2                    ; No, okay to exit
  446.  
  447.                Move.L        -4(A0),-4(A1)        ; right := left
  448.                Move.L        D1,-4(A0)            ; left := right
  449.  
  450.        @2:     PopRts        ArgSize                ; Pop arguments off stack & retu
  451.  
  452.                 EndProc
  453.  
  454. ********************************************************************************************
  455. *                FUNCTION PtInVRect (pt: VPoint; r: VRect): BOOLEAN;
  456. *                Returns true if the given point lies within the given rectangle.
  457. *
  458. *                Trashes:    A0,A1,D0
  459. ********************************************************************************************
  460. PtInVRect        Func        Export
  461.  
  462. StackFrame        Record        0,Increment
  463. RetAddr         Ds.L        1
  464. r                Ds.L        1
  465. pt                Ds.L        1
  466. ArgSize         Equ         *-4
  467. RetValue        Ds.W        1
  468.                 EndR
  469.  
  470.                 With        StackFrame
  471.                 
  472.                 Clr.B        RetValue(SP)        ; Prime result to FALSE
  473.  
  474.                 MoveA.L     pt(SP),A0            ; Get address of pt.
  475.                 Move.L        A0,D0                ; Save address
  476.                 MoveA.L     r(SP),A1            ; Get address of r.
  477.                 CmpM.L        (A0)+,(A1)+         ; If pt.v < r.top then fail.
  478.                 Bgt.S        @2
  479.                 CmpM.L        (A0)+,(A1)+         ; If pt.h < r.left then fail.
  480.                 Bgt.S        @2
  481.  
  482.                 MoveA.L     D0,A0                ; Get address of pt, again.
  483.                 CmpM.L        (A0)+,(A1)+         ; If pt.v >= r.bottom then fail.
  484.                 Ble.S        @2
  485.                 CmpM.L        (A0)+,(A1)+         ; If pt.h >= r.right then fail.
  486.                 Ble.S        @2
  487.         
  488.         @1:     AddQ.B        #1,RetValue(SP)
  489.  
  490.         @2:     PopRts        ArgSize             ; Pop arguments off stack and return.
  491.  
  492.                 EndProc
  493.  
  494. ********************************************************************************************
  495. *                FUNCTION EmptyVRect (r: VRect): BOOLEAN;
  496. *                Returns true if the given rectangle is empty.
  497. *
  498. *                Trashes:    A0,A1,D0
  499. ********************************************************************************************
  500. EmptyVRect        Func        Export
  501.  
  502. StackFrame        Record        0,Increment
  503. RetAddr         Ds.L        1
  504. r                Ds.L        1
  505. ArgSize         Equ         *-4
  506. RetValue        Ds.W        1
  507.                 EndR
  508.  
  509.                 With        StackFrame
  510.  
  511.                 MoveA.L     r(SP),A0            ; Address of r.topLeft in A0.
  512.                 Lea         8(A0),A1            ; Address of r.botRight in A1.
  513.  
  514.                 CmpM.L        (A0)+,(A1)+         ; Compare top to bottom.
  515.                 Ble.S        @1                    ; Fail if top >= bottom
  516.                 CmpM.L        (A0)+,(A1)+         ; Compare left and right.
  517.  
  518.         @1:     Sle         D0
  519.                 Neg.B        D0
  520.                 Move.B        D0,RetValue(SP)
  521.  
  522.                 PopRts        ArgSize             ; Pop arguments off stack and return.
  523.  
  524.                 EndProc
  525.  
  526. ********************************************************************************************
  527. *                FUNCTION EqualVRect (r1, r2: VRect): BOOLEAN;
  528. *                Returns true if the given rectangles are equal.
  529. *
  530. *                Trashes:    A0,A1,D0
  531. ********************************************************************************************
  532. EqualVRect        Func        Export
  533.  
  534. StackFrame        Record        0,Increment
  535. RetAddr         Ds.L        1
  536. r2                Ds.L        1
  537. r1                Ds.L        1
  538. ArgSize         Equ         *-4
  539. RetValue        Ds.W        1
  540.                 EndR
  541.  
  542.                 With        StackFrame
  543.  
  544.                 MoveA.L     r1(SP),A0            ; Get address of r1.
  545.                 MoveA.L     r2(SP),A1            ; Get address of r2.
  546.  
  547.                 CmpM.L        (A0)+,(A1)+         ; Compare top.
  548.                 Bne.S        @1
  549.                 CmpM.L        (A0)+,(A1)+         ; Compare left.
  550.                 Bne.S        @1
  551.                 CmpM.L        (A0)+,(A1)+         ; Compare bottom.
  552.                 Bne.S        @1
  553.                 CmpM.L        (A0)+,(A1)+         ; Compare right.
  554.  
  555.         @1:     Seq         D0
  556.                 Neg.B        D0
  557.                 Move.B        D0,RetValue(SP)
  558.  
  559.                 PopRts        ArgSize             ; Pop arguments off stack and return.
  560.  
  561.                 EndProc
  562.  
  563. ********************************************************************************************
  564. *                FUNCTION LengthVRect (r: VRect; vhs: VHSelect): VCoordinate;
  565. *                Returns the size of the rectangle in the given dimension.
  566. *
  567. *                Trashes:    A0,A1,D0
  568. ********************************************************************************************
  569. LengthVRect     Func        Export
  570.  
  571. StackFrame        Record        0,Increment
  572. RetAddr         Ds.L        1
  573. vhs             Ds.W        1
  574. r                Ds.L        1
  575. ArgSize         Equ         *-4
  576. RetValue        Ds.L        1
  577.                 EndR
  578.  
  579.                 With        StackFrame
  580.  
  581.                 MoveA.L     r(SP),A0            ; Get address of r. (Points at r.top.)
  582.                 Tst.B        vhs(SP)             ; Are we getting vertical distance?
  583.                 Beq.s        @1                    ; Yes, branch.
  584.  
  585.                 AddQ.W        #4,A0                ; No, point to r.left.
  586.  
  587.         @1:     Move.L        8(A0),D0            ; get r.botRight[vhs].
  588.                 Sub.L        (A0),D0             ; D0 := r.botRight[vhs] - r.topLeft[vhs].
  589.                 Move.L        D0,RetValue(SP)     ; Set result.
  590.  
  591.                 PopRts        ArgSize             ; Pop arguments off stack and return.
  592.  
  593.                 EndProc
  594.  
  595. ********************************************************************************************
  596. *                PROCEDURE PinVRect (r: VRect; VAR pt: VPoint);
  597. *                Pins the given point to the given rectangle.
  598. *
  599. *                Trashes:    A0,A1,D0
  600. ********************************************************************************************
  601. PinVRect        Proc        Export
  602.  
  603. StackFrame        Record        0,Increment
  604. RetAddr         Ds.L        1
  605. pt                Ds.L        1
  606. r                Ds.L        1
  607. ArgSize         Equ         *-4
  608.                 EndR
  609.  
  610.                 With        StackFrame
  611.  
  612.                 MoveA.L     r(SP),A0            ; Get address of r into A0.
  613.                 MoveA.L     pt(SP),A1            ; Get address of pt into A1.
  614.  
  615.                 Move.L        (A1),D0             ; D0 := pt.v.
  616.                 Cmp.L        (A0),D0             ; Is pt.v < r.top?
  617.                 Bge.S        @1                    ; No, branch.
  618.                 Move.L        (A0),D0             ; Yes, pt.v := r.top.
  619. @1
  620.                 Cmp.L        8(A0),D0            ; Is pt.v >= r.bottom?
  621.                 Blt.S        @2                    ; No, branch.
  622.                 Move.L        8(A0),D0            ; Yes, pt.v := r.bottom.
  623.                 Sub.L        #1,D0                ; pt.v := r.bottom - 1;
  624. @2
  625.                 Move.L        D0,(A1)+            ; pt.v := D0
  626.  
  627.                 Move.L        (A1),D0             ; D0 := pt.h.
  628.                 Cmp.L        4(A0),D0            ; Is pt.h < r.left?
  629.                 Bge.S        @3                    ; No, branch.
  630.                 Move.L        4(A0),D0            ; Yes, pt.h := r.left.
  631. @3
  632.                 Cmp.L        12(A0),D0            ; Is pt.h >= r.right?
  633.                 Blt.S        @4                    ; No, branch.
  634.                 Move.L        12(A0),D0            ; Yes, pt.h := r.right.
  635.                 Sub.L        #1,D0                ; pt.h := r.right - 1.
  636. @4
  637.                 Move.L        D0,(A1)             ; pt.h := D0.
  638.  
  639.                 PopRts        ArgSize             ; Pop arguments off stack and return.
  640.  
  641.                 EndProc
  642.  
  643. ********************************************************************************************
  644. *                FUNCTION SectVRect (src1, src2: VRect; VAR dstRect: VRect): BOOLEAN;
  645. *                Returns true if src1 and src2 intersect.  dstRect is set to the intersection
  646. *                or (0,0)/(0,0) if src1 and src2 don't intersect.
  647. *
  648. *                Trashes:    A0,A1,D0,D1
  649. ********************************************************************************************
  650. SectVRect        Func        Export
  651.                 Import        MinA0A1,MaxA0A1,ValidateRect
  652.  
  653. StackFrame        Record        0,Increment
  654. savedA2         Ds.L        1
  655. RetAddr         Ds.L        1
  656. dstRect         Ds.L        1
  657. src2            Ds.L        1
  658. src1            Ds.L        1
  659. ArgSize         Equ         *-8
  660. RetValue        Ds.W        1
  661.                 EndR
  662.  
  663.                 With        StackFrame
  664.                 Move.L        A2,-(SP)            ; Save A2.
  665.  
  666.                 MoveA.L     src1(SP),A0         ; Get address of src1.
  667.                 MoveA.L     src2(SP),A1         ; Get address of src2.
  668.                 MoveA.L     dstRect(SP),A2        ; Get address of dstRect.
  669.  
  670.                 bsr            MaxA0A1             ; D0 gets max of src1.top and src2.top.
  671.                 Move.L        D0,(A2)+            ; Store it in dstRect.top.
  672.                 bsr            MaxA0A1             ; D0 gets max of src1.left and src2.left.
  673.                 Move.L        D0,(A2)+            ; Store it in dstRect.left.
  674.                 bsr            MinA0A1             ; D0 gets min of src1.bottom and src2.bottom.
  675.                 Move.L        D0,(A2)+            ; Store it in dstRect.bottom.
  676.                 bsr            MinA0A1             ; D0 gets min of src1.right and src2.right.
  677.                 Move.L        D0,(A2)             ; Store it in dstRect.right.
  678.  
  679.                 Lea         -12(A2),A0            ; Now validate dstRect.
  680.                 bsr            ValidateRect
  681.                 Move.B        D0,RetValue(SP)
  682.  
  683.                 MoveA.L     (SP)+,A2            ; Restore A2.
  684.  
  685.                 PopRts        ArgSize             ; Pop arguments off stack and return.
  686.  
  687.                 EndProc
  688.  
  689. ********************************************************************************************
  690. *                PROCEDURE UnionVRect (src1, src2: VRect; VAR dstRect: VRect);
  691. *                Returns in dstRect the union of src1 and src2.
  692. *
  693. *                Trashes:    A0,A1,D0,D1
  694. ********************************************************************************************
  695. UnionVRect        Proc        Export
  696.                 Import        MinA0A1,MaxA0A1
  697.  
  698. StackFrame        Record        0,Increment
  699. savedA2         Ds.L        1
  700. RetAddr         Ds.L        1
  701. dstRect         Ds.L        1
  702. src2            Ds.L        1
  703. src1            Ds.L        1
  704. ArgSize         Equ         *-8
  705.                 EndR
  706.  
  707.                 With        StackFrame
  708.                 Move.L        A2,-(SP)            ; Save A2.
  709.  
  710.                 MoveA.L     src1(SP),A0         ; Get address of src1.
  711.                 MoveA.L     src2(SP),A1         ; Get address of src2.
  712.                 MoveA.L     dstRect(SP),A2        ; Get address of dstRect.
  713.  
  714.                 bsr            MinA0A1             ; D0 gets max of src1.top and src2.top.
  715.                 Move.L        D0,(A2)+            ; Store it in dstRect.top.
  716.                 bsr            MinA0A1             ; D0 gets max of src1.left and src2.left.
  717.                 Move.L        D0,(A2)+            ; Store it in dstRect.left.
  718.                 bsr            MaxA0A1             ; D0 gets min of src1.bottom and src2.bottom.
  719.                 Move.L        D0,(A2)+            ; Store it in dstRect.bottom.
  720.                 bsr            MaxA0A1             ; D0 gets min of src1.right and src2.right.
  721.                 Move.L        D0,(A2)             ; Store it in dstRect.right.
  722.  
  723.                 MoveA.L     (SP)+,A2            ; Restore A2.
  724.  
  725.                 PopRts        ArgSize             ; Pop arguments off stack and return.
  726.  
  727.                 EndProc
  728.  
  729. ********************************************************************************************
  730. *                MaxA0A1
  731. *                Returns the maximum of (A0)+ and (A1)+ in D0.
  732. *
  733. *                Trashes:    A0,A1,D0,D1
  734. ********************************************************************************************
  735. MaxA0A1         Proc
  736.  
  737.                 Move.L        (A0)+,D0
  738.                 Move.L        (A1)+,D1
  739.                 Cmp.L        D0,D1
  740.                 Ble.S        @1
  741.                 Move.L        D1,D0
  742. @1
  743.                 Rts
  744.  
  745.                 EndProc
  746.  
  747. ********************************************************************************************
  748. *                MinA0A1
  749. *                Returns the minimum of (A0)+ and (A1)+ in D0.
  750. *
  751. *                Trashes:    A0,A1,D0,D1
  752. ********************************************************************************************
  753. MinA0A1         Proc
  754.  
  755.                 Move.L        (A0)+,D0
  756.                 Move.L        (A1)+,D1
  757.                 Cmp.L        D0,D1
  758.                 Bge.S        @1
  759.                 Move.L        D1,D0
  760. @1
  761.                 Rts
  762.  
  763.                 EndProc
  764.  
  765. ********************************************************************************************
  766. *                ValidateRect
  767. *                Validates the rectangle at (A0).  The rect is considered valid if
  768. *                (left < right) and (top < bottom).    If the rect is valid then D0 returns 1
  769. *                in the low byte, else D0 returns zero in the low byte and the rect is set
  770. *                to (0,0)/(0,0).
  771. *
  772. *                Trashes:    A0,D0,D1
  773. ********************************************************************************************
  774. ValidateRect    Proc
  775.  
  776.                 MoveQ        #1,D0                ; Seed result to true
  777.                 Move.L        8(A0),D1            ; D1 := rect.bottom.
  778.                 Cmp.L        (A0),D1             ; Compare top to bottom.
  779.                 Ble.S        @1                    ; It's invalid if bottom <= top.
  780.                 Move.L        12(A0),D1            ; D1 := rect.right.
  781.                 Cmp.L        4(A0),D1            ; Compare left and right.
  782.                 Bgt.S        @2                    ; If right > left, then it's valid & branch.
  783.  
  784.         @1:     MoveQ        #0,D0
  785.                 Move.L        D0,(A0)+            ; It's an invalid rect.  Set to zeros.
  786.                 Move.L        D0,(A0)+
  787.                 Move.L        D0,(A0)+
  788.                 Move.L        D0,(A0)
  789.  
  790.         @2:     Rts
  791.  
  792.                 EndProc
  793.  
  794.                 End
  795. ;AMEN